import LoginStore from '../../pages/login/store.js';
import { isAuthorization } from '../../utils/util.js';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    adjustCls: {
      type: String,
      value: '',
      observer: function (newVal, oldVal, changedPath) {

      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    tabs: [],
    activeItem:{}
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setTabs: function (v, callback, activeItem) {
      let me = this;
      if (!activeItem) {
        activeItem = v[0];
        if (activeItem.name == 'introduction') {
          activeItem = v[1];
        }
      }
      this.setData({
        tabs: v,
        activeItem: activeItem
      }, function(){
        callback(activeItem)
      })
    },
    // setActiveTab: function(activeItem) {
    //   this.data.tabs.forEach((item, index) => {
    //     if (item.key == activeItem.key) {
    //       item.active = true;
    //     } else {
    //       item.active = false;
    //     }
    //   })
    //   this.setData({
    //     tabs: this.data.tabs
    //   })
    // },
    _click(e) {
      let item = e.currentTarget.dataset.item;
      this.triggerEvent('tabclick', item);
      if (item.name == 'introduction' || item.name == 'myJoin'){
        return;
      }
      this.setData({
        activeItem: item
      });
      //不是webview的时候才切换选中样式
      // if (!item.page) {
      //   this.setActiveTab(item);
      // }
    },
    _myContest:function(e){
      if (!isAuthorization(e)) {
        return;
      }
      LoginStore.validateLogin(() => {
        this._click(e);
      });
    }
  }
})